package com.restaurantonlineorder.oauth.handler;

import com.restaurantonlineorder.oauth.utils.ResponseUtil;
import com.restaurantonlineorder.response.BaseResult;
import com.restaurantonlineorder.response.BaseResultCode;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 熊宇
 * @date 2022/5/14 22:49
 * @description 认证失败处理逻辑
 */

@Component
public class DefaultAuthenticationFailureHandler implements AuthenticationFailureHandler {
    @Override
    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {
        ResponseUtil.sendMessage(response, BaseResult.failure(BaseResultCode.USER_LOGIN_ERROR));
    }
}
